package com.gx.utils;

import lombok.extern.slf4j.Slf4j;

/**
 * @author lpj
 */
@Slf4j
public class DataSourceThreadLocal {

    /**
     * 线程级别的私有变量
     */
    private static final ThreadLocal<String> CONTEXT_HOLDER = new ThreadLocal<>();

    /**
     * 切换数据源
     */
    public static void setDataSource(String dataSourceName) {
        CONTEXT_HOLDER.set(dataSourceName);
    }

    public static String getDataSource() {
        return CONTEXT_HOLDER.get();
    }


    /**
     * 删除数据源
     */
    public static void removeDataSource() {
        CONTEXT_HOLDER.remove();
    }
}
